nclude <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() 
{
    string ret, s = "0123456789ABCDEF";
    int m,n;
    cin >> m >> n;
    bool flag = false;

    //小于等于0情况特殊处理
    if(m == 0)
        ret+= '0';
    
    if(m < 0)
    {
        flag = true;
        m = -m;
    }

    //利用映射将每进制位数写入到ret中
    while(m)
    {
        ret+= s[m % n];
        m /= n;
    }

    //负数情况下插入字符'-'
    if(flag)
    {
        ret += '-';
    }

    //整体逆置即可
    reverse(ret.begin(), ret.end());

    cout << ret << endl;

}
// 64 位输出请用 printf("%lld")
